package com.acane.instagram.service.impl;

import com.acane.instagram.mapper.PostMapper;
import com.acane.instagram.mapper.ReviewMapper;
import com.acane.instagram.pojo.Post;
import com.acane.instagram.service.ReviewService;
import com.acane.instagram.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReviewServiceImpl extends ServiceImpl<PostMapper, Post> implements ReviewService {

    @Autowired
    private ReviewMapper reviewMapper;

    @Autowired
    private PostMapper postMapper;

    @Autowired
    private UserService userService;

    @Override
    public List<Post> searchPosts(String userName, String content, Integer status, String startTime, String endTime, Integer page, Integer size) {
        // 计算分页偏移量
        int offset = (page - 1) * size;

        System.out.println("===============================================实现类收到的status:" + status);
        List<Post> posts = reviewMapper.searchPosts(userName, content, status, startTime, endTime, offset, size);

        // 补充用户信息和资源URL
        for (Post post : posts) {
            post.setUser(userService.getUserById(post.getUserId()));
            post.setUrls(postMapper.selectPostWithImages(post.getId()));
        }
        return posts;

    }
}
